package com.sl.biz.modular.process.service.impl;

import com.sl.biz.modular.process.controller.request.ProcessLogDetailByTidRequest;
import com.sl.biz.modular.process.controller.request.ProcessLogListByConditionRequest;
import com.sl.biz.modular.process.controller.request.ProcessLogUpdateStateRequest;
import com.sl.biz.modular.process.service.ProcessLogBizService;
import com.sl.common.page.PageList;
import com.sl.core.engine.log.store.LoggerStoreFactory;
import com.sl.core.engine.log.store.domain.bo.ProcessLogListByConditionBO;
import com.sl.core.engine.log.store.domain.dto.LogDetailDTO;
import com.sl.core.engine.log.store.domain.dto.MainLogDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class ProcessLogBizServiceImpl implements ProcessLogBizService {
    @Override
    public List<MainLogDTO> listByCondition(ProcessLogListByConditionRequest list) {
        //   return List.of();

        ProcessLogListByConditionBO processLogListByConditionBO = new ProcessLogListByConditionBO();
        processLogListByConditionBO.setStartDate(list.getStartDate());
        processLogListByConditionBO.setEndDate(list.getEndDate());
        processLogListByConditionBO.setProcessId(list.getProcessId());
        processLogListByConditionBO.setKeywords(list.getKeywords());
        processLogListByConditionBO.setTid(list.getTid());
        processLogListByConditionBO.setInstanceId(list.getInstanceId());
        processLogListByConditionBO.setCurrent(list.getCurrent());
        processLogListByConditionBO.setSize(list.getSize());

        List<MainLogDTO> mainLogDTOS = LoggerStoreFactory.INSTANCE.listByCondition(processLogListByConditionBO,list.getLogStoreTypeCode());

        PageList<MainLogDTO> dtoPageList = PageList.of(mainLogDTOS);
        return dtoPageList;

    }

    @Override
    public List<LogDetailDTO> getDetailByTid(ProcessLogDetailByTidRequest list) {
        List<LogDetailDTO> detailByTid = LoggerStoreFactory.INSTANCE.getDetailByTid(list.getTid(), list.getLogTime(),list.getLogStoreTypeCode());
        return detailByTid;
    }

    @Override
    public Boolean updateStateById(ProcessLogUpdateStateRequest list) {
        Boolean result = LoggerStoreFactory.INSTANCE.updateStateById(list.getId(), list.getState());
        return result;
    }
}
